package cn.kgc.fxy.smbms.service.impl;

import cn.kgc.fxy.smbms.entity.User;
import cn.kgc.fxy.smbms.mapper.UserMapper;
import cn.kgc.fxy.smbms.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public User findLogin(String userCode, String userPassword) {
        User user = userMapper.selectLogin(userCode,userPassword);
        return user;
    }

    @Override
    public PageInfo<User> findAllUser(User condition,Integer pageNum,Integer pageSize) {
        if (pageNum == null){
            pageNum = 1;
        }

        PageHelper.startPage(pageNum,pageSize);
        List<User> userList = userMapper.selectAllUser(condition);
        PageInfo<User> pageInfo = new PageInfo<>(userList);
        return pageInfo;
    }

    @Override
    public User findByUserPassword(Long userId) {
        User user = userMapper.selectByUserPassword(userId);
        return user;
    }

    @Override
    public void modifyPwd(String userPassword, Long userId) {
        userMapper.updatePwd(userPassword,userId);
    }

    @Override
    public User findView(Long userId) {
        User user = this.userMapper.selectView(userId);
        return user;
    }

    @Override
    public void addUser(User user) {
        this.userMapper.insertUser(user);
    }

    @Override
    public Integer findUserCount(String userCode) {
        Integer findUserCount=userMapper.selectUserCount(userCode);
        return findUserCount;
    }

    @Override
    public void modifyUser(User user) {
        this.userMapper.updateUser(user);
    }

    @Override
    public void removeUser(Long userId) {
        userMapper.deleteUser(userId);
    }

    @Override
    public User findById(Long userId) {
        User user = this.userMapper.selectById(userId);
        return user;
    }

}
